#include "level.h"
#include <QObject>

#include "database.h"
#include "earthdawn.h"
#include "character.h"

Level::Level(const QString &descriptor)
    : _descriptor(descriptor)
{
    _useRank = descriptor.contains("Rang",Qt::CaseInsensitive);
    _useAttribute = false;
    foreach(ed::Attribute a, ed::Attribute::values())
    {
      if (descriptor.contains((QString)a,Qt::CaseInsensitive))
      {
        _useAttribute = true;
        _attribute = a;
        break;
      }
    }
}

QString Level::valueString(int rank, Character *c)
{
  if (_useRank && !_useAttribute) return QString::number(rank);
  if (_useRank && _useAttribute)
  {
    return QString::number(rank + c->attributeLevel(_attribute)) + " / " + ed::poolString(Database::dicePool(rank+c->attributeLevel(_attribute)));
  }
  return "-";
}

Level::operator QString()
{
    if (!_useRank && !_useAttribute) return _descriptor;

    return (_useRank ? QObject::trUtf8("Rang") : "")
            + (_useRank && _useAttribute ? " + " : "")
            + (_useAttribute ? (QString)_attribute : "");
}
